import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { FahunItem } from "./FahunItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { FahunItemInfo } from "./FahunItemInfo";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
//class FahunItemCellRenderer
    
    export  class FahunItemCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            this.buttonMode = true;
            this.mouseChildren = false;
            addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseOver);
            addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onMouseOut);
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBitmap(ImagesConst.PropBg, 0, 0, this);
            this._fahunItem = new FahunItem(false, 60, 60);
            this._fahunItem.x = 5;
            this._fahunItem.y = 5;
            this.addChild(this._fahunItem);
            this._lineBitmap = ObjCreate.createBg(0, 73, 135, 2, this, ImagesConst.SplitLine);
            this._selectedBg = GlobalClass.getBitmap(ImagesConst.SelectedBg);
            this._selectedBg.width = 140;
            this._selectedBg.height = 70;
            this._breakBitmap = new Object /* flash.display.Bitmap */();
            this._breakBitmap.x = 0;
            this._breakBitmap.y = 0;
            this._nameTxt = ObjCreate.createGTextField("", 75, 14, 60, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt.mouseEnabled = false;
            this._levelTxt = ObjCreate.createGTextField("", 75, 40, 60, 20, this, GlobalStyle.textFormatGreen);
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._levelTxt.mouseEnabled = false;
            LoaderHelp.addResCallBack(ResFileConst.fahun, this.onLoadHandler);
            return;
        }

        /* internal  */onLoadHandler(): void
        {
            this._breakBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.FahunTPLabel);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._fahunItemInfo = arg1 as FahunItemInfo;
            this._fahunItem.fahunItemInfo = this._fahunItemInfo;
            if (this._fahunItemInfo && this._fahunItemInfo.index == 5) 
            {
                DisplayUtil.removeMe(this._lineBitmap);
            }
            if (this._fahunItemInfo) 
            {
                if (this._fahunItemInfo.isEnable) 
                {
                    this._fahunItem.filters = null;
                    this.mouseEnabled = true;
                    this.mouseChildren = true;
                }
                else 
                {
                    this._fahunItem.filters = [FilterConst.colorFilter];
                    this.mouseEnabled = false;
                    this.mouseChildren = false;
                }
                if (this._fahunItemInfo.isNeedBreak) 
                {
                    if (!this._breakBitmap.parent) 
                    {
                        this.addChild(this._breakBitmap);
                    }
                }
                else 
                {
                    DisplayUtil.removeMe(this._breakBitmap);
                }
                this._nameTxt.text = GameDefConfig.instance.getFahunName(this._fahunItemInfo.index);
                this._levelTxt.text = "LV." + this._fahunItemInfo.level;
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this._fahunItemInfo.isEnable) 
            {
                if (!this._selectedBg.parent) 
                {
                    addChildAt(this._selectedBg, 0);
                }
            }
            else 
            {
                DisplayUtil.removeMe(this._selectedBg);
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._selectedBg.parent) 
            {
                addChildAt(this._selectedBg, 0);
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!_selected) 
            {
                if (this._selectedBg.parent) 
                {
                    removeChild(this._selectedBg);
                }
            }
            return;
        }

        /* internal */ /* var */_fahunItem: FahunItem;

        /* internal */ /* var */_lineBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_selectedBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_breakBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_levelTxt: GTextFiled;

        /* internal */ /* var */_fahunItemInfo: FahunItemInfo;
    }
